package com.atguigu.controller;


import com.atguigu.entity.BaseSaleProperty;
import com.atguigu.entity.ProductSalePropertyKey;
import com.atguigu.entity.ProductSpu;
import com.atguigu.result.RetVal;
import com.atguigu.service.BaseSalePropertyService;
import com.atguigu.service.ProductSalePropertyKeyService;
import com.atguigu.service.ProductSpuService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apiguardian.api.API;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 基本销售属性表 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/product")
@Api(tags = "spu管理接口")
public class ProductSpuController {
    @Autowired
    private ProductSpuService productSpuService;
    @Autowired
    private BaseSalePropertyService baseSalePropertyService;
    //http://127.0.0.1/product/queryProductSpuByPage/1/10/61
    @ApiOperation("获取spu列表并分页展示")
    @GetMapping("queryProductSpuByPage/{page}/{size}/{category3Id}")
    public RetVal queryProductSpuByPage(@PathVariable("page") Long page,
                                        @PathVariable("size") Long size,
                                        @PathVariable("category3Id") Long category3Id){
        Page<ProductSpu> productSpuPage = new Page<>(page,size);
        QueryWrapper<ProductSpu> wrapper = new QueryWrapper<>();
        wrapper.eq("category3_id",category3Id);

        IPage<ProductSpu> productSpuData = productSpuService.page(productSpuPage, wrapper);
        return RetVal.ok(productSpuData);
    }

    //http://127.0.0.1/product/queryAllSaleProperty
    //7查询所有销售属性
    @ApiOperation("查询所有销售属性")
    @GetMapping("queryAllSaleProperty")
    public RetVal queryAllSaleProperty() {
        List<BaseSaleProperty> list = baseSalePropertyService.list(null);
        return RetVal.ok(list);
    }

    //3.添加SPU信息实战 http://127.0.0.1/product/saveProductSpu
    @PostMapping("saveProductSpu")
    @ApiOperation("保存spu")
    public RetVal saveProductSpu(@RequestBody ProductSpu productSpu) {
        productSpuService.saveProductSpu(productSpu);
        return RetVal.ok();
    }
}

